package com.duyj.rule.model.datarow;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class RowKey implements Serializable {
	/**
	 * 序列号
	 */
	private static final long serialVersionUID = -493350613637241106L;
	/**
	 * 行id属性
	 */
	private String rowId;
	/**
	 * 行索引
	 */
	private Integer rowIndex;
	/**
	 * 扩展信息
	 */
	Map<String, Object> map = new HashMap<>(5);
	
	/**
	 * 区域id
	 */
	private String areaId;

	/**
	 * <构造函数>
	 */
	public RowKey() {
		super();
	}

	/**
	 * <构造函数>
	 *
	 * @param rowId
	 */
	public RowKey(String rowId) {
		super();
		this.rowId = rowId;
	}

	/**
	 * <构造函数>
	 *
	 * @param rowId
	 */
	public RowKey(String rowId, Integer rowIndex) {
		super();
		this.rowId = rowId;
		this.rowIndex = rowIndex;
	}
	/**
	 * <构造函数>
	 *
	 * @param rowId
	 * @param rowIndex
	 * @param areaId
	 */
	public RowKey(String rowId, Integer rowIndex, String areaId) {
		super();
		this.rowId = rowId;
		this.rowIndex = rowIndex;
		this.areaId = areaId;
	}

	/**
	 * @return rowId
	 */
	public String getRowId() {
		return rowId;
	}

	/**
	 * @param rowId
	 */
	public void setRowId(String rowId) {
		this.rowId = rowId;
	}

	public void setKeyValue(String key, Object value) {
		map.put(key, value);
	}

	public Object getValue(String key) {
		return map.get(key);
	}

	public Integer getRowIndex() {
		return rowIndex;
	}

	public void setRowIndex(Integer rowIndex) {
		this.rowIndex = rowIndex;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getAreaId() {
		return areaId;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof RowKey)) {
			return false;
		}
		RowKey rowKey = (RowKey) o;
		if (StringUtils.isNotEmpty(rowId)) {
			return Objects.equals(rowId, rowKey.rowId);
		} else {
			return Objects.equals(map, rowKey.map);
		}
	}

	@Override
	public int hashCode() {
		if (StringUtils.isNotEmpty(rowId)) {
			return Objects.hash(rowId);
		} else {
			return Objects.hash(map);
		}
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("rowId", rowId).append("rowIndex", rowIndex).append("map", map)
				.toString();
	}
}
